//
//  UserAccountTool.swift
//  KKWB
//
//  Created by KSY-iOS on 17/1/13.
//  Copyright © 2017年 KK. All rights reserved.
//

import UIKit

class UserAccountViewModel {

    static let shareInstance: UserAccountViewModel = UserAccountViewModel()
    
    // MARK:- 计算属性
    var account: UserAccount?
    
    var accountPath: String {
        
        var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        path = "\(path)/account.plist"
        
        return path
    }
    
    var isLogin: Bool {
        
        if account == nil {
            return false
        }
        
        if let userExpiresDate = account?.expires_date {
            return userExpiresDate.compare(Date()) == ComparisonResult.orderedDescending
        }
        
        return false
    }
    
    init() {
        
        account = NSKeyedUnarchiver.unarchiveObject(withFile: accountPath) as? UserAccount
    }
}
